package org.apache.ibatis.transaction;

import org.apache.ibatis.session.TransactionIsolationLevel;

import javax.sql.DataSource;
import java.sql.Connection;
import java.util.Properties;

/**
 * Creates {@link Transaction} instances.
 * 事务工厂：创建事务实例
 *
 * @author Clinton Begin
 */
public interface TransactionFactory {

    /**
     * Sets transaction factory custom properties.
     * 配置TransactionFactory对象，一般紧跟在创建完成之后，完成对TransactionFactory的自定义配置
     *
     * @param props
     */
    void setProperties(Properties props);

    /**
     * Creates a {@link Transaction} out of an existing connection.
     * 在指定的连接上创建Transaction(事务)对象
     *
     * @param conn Existing database connection
     * @return Transaction
     * @since 3.1.0
     */
    Transaction newTransaction(Connection conn);

    /**
     * Creates a {@link Transaction} out of a datasource.
     * 从指定数据源中获取数据库连接，并在此连接之上创建Transaction(事务)对象
     *
     * @param dataSource DataSource to take the connection from(数据源)
     * @param level      Desired isolation level (隔离级别)
     * @param autoCommit Desired autocommit (自动提交)
     * @return Transaction
     * @since 3.1.0
     */
    Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit);

}
